package com.c3w.synchro.member.bean;

import com.c3w.synchro.common.bean.Bean;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import java.util.Collection;
import java.util.HashSet;

/**
 * User: magirard
 * Date: 12-10-03
 */
@Entity
public class Team extends Bean {

    private String name;

    @OneToMany(fetch = FetchType.LAZY)
    private Collection<Coach> coaches;

    private int ageSum;

    private int stream;

    @OneToMany(fetch = FetchType.LAZY)
    private Collection<Athlete> athletes;

    @OneToMany(fetch = FetchType.LAZY)
    private Collection<Athlete> substitutes;

    private long clubId;


    public Team() {
        this.athletes = new HashSet<>();
        this.substitutes = new HashSet<>();

        this.ageSum = 0;
    }

    public int getAgeSum() {
        return ageSum;
    }

    public void addToAgeSum(int age) {
        this.ageSum += age;
    }

    public void setAgeSum(int ageSum) {
        this.ageSum = ageSum;
    }

    public Collection<Coach> getCoaches() {
        return coaches;
    }

    public void setCoaches(Collection
                                   <Coach> coaches) {
        this.coaches = coaches;
    }

    public long getClubId() {
        return clubId;
    }

    public void setClubId(long clubId) {
        this.clubId = clubId;
    }

    public Collection<Athlete> getAthletes() {
        return athletes;
    }

    public void setAthletes(Collection<Athlete> memberList) {
        this.athletes = memberList;
    }

    public Athlete getFirstMember() {
        Athlete first = null;
        if (athletes != null) {
            first = athletes.iterator().next();
        }

        return first;
    }

    public void addAthlete(Athlete athlete) {
        athletes.add(athlete);
    }

    public Collection<Athlete> getSubstitutes() {
        return substitutes;
    }

    public void setSubstitutes(Collection<Athlete> substitutes) {
        this.substitutes = substitutes;
    }

    public void addSubstitute(Athlete substitute) {
        substitutes.add(substitute);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getStream() {
        return stream;
    }

    public void setStream(int stream) {
        this.stream = stream;
    }
}
